cmake_minimum_required(VERSION 3.27)
project(Ogre3D)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

# 添加QML调试标志
#add_compile_definitions(QT_QML_DEBUG)
#if(CMAKE_BUILD_TYPE STREQUAL "Debug")
#    add_definitions(-DQT_QML_DEBUG)
#endif()

add_definitions(-DProject_KT)
#add_definitions(-DProject_SQ)
#add_definitions(-DProject_SSQK)

set(CMAKE_PREFIX_PATH "D:/Qt/5.12.5/msvc2017_64/lib/cmake")

set(OGRE_PATH "D:/OGRE-Next/ogre-next-master/build/install")
link_directories("${OGRE_PATH}/lib/Debug")

# 添加不参与编译的资源文件到工程中
function(add_folder_as_target folder)
	file(GLOB FILES "${folder}/*")
	string(REPLACE "/" "_" target_name ${folder})
	add_custom_target(${target_name} SOURCES ${FILES})
endfunction()
add_folder_as_target("res/qml")
add_folder_as_target("res/glsl")
add_folder_as_target("res/object")
add_folder_as_target("res/image")
add_folder_as_target("res/cfg")

add_custom_target("ToDo" SOURCES "ToDo.md")

# 添加参与编译执行的目录
file(GLOB_RECURSE SRC_FILES "src/*")
file(GLOB_RECURSE INCLUDE_SRC_FILES "external/src/*" "external/sol/lua/*.c")

add_executable(${PROJECT_NAME} ${SRC_FILES} main.cpp)
target_sources(${PROJECT_NAME} PRIVATE ${INCLUDE_SRC_FILES})

find_package(Qt5 COMPONENTS Core Quick Qml Gui Concurrent Network REQUIRED)
find_package(OpenGL REQUIRED) #OpenGL not Qt5 OpenGL

if (Qt5Core_FOUND OR Qt6Core_FOUND)
	add_definitions(-D__QT__)
endif()

#if (OPENGL_FOUND)
#    message(STATUS "OpenGL found: ${OPENGL_LIBRARIES}")
#else()
#    message(FATAL_ERROR "OpenGL not found!")

target_include_directories(${PROJECT_NAME} PRIVATE "${OGRE_PATH}/include/OGRE-Next"
												   "${OGRE_PATH}/include/OGRE-Next/Hlms/Common"
												   "${OGRE_PATH}/include/OGRE-Next/Hlms/Pbs"
												   "${OGRE_PATH}/include/OGRE-Next/Hlms/Unlit"
												   "external/Common/include"
												   "external" "external/sol")

target_link_libraries(${PROJECT_NAME}
	Qt5::Core Qt5::Quick Qt5::Qml Qt5::Gui Qt5::Concurrent Qt5::Network
	${OPENGL_LIBRARIES}
	OgreNextMain_d.lib
	OgreNextHlmsPbs_d.lib
	OgreNextHlmsUnlit_d.lib
	OgreNextOverlay_d.lib
)

source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/src FILES ${SRC_FILES})

#add_definitions(-D_SILENCE_STDEXT_ARR_ITERS_DEPRECATION_WARNING)